<?php

namespace app\modules\admin\controllers;

use app\common\controllers\AccessController;
use app\modules\admin\forms\order\AdjustForm;
use app\modules\admin\services\GoodsOrderService;
use yii\base\UserException;

class GoodsOrderController extends AccessController{

    //搜索
    public function actionSearch(){
        $merchant_id = \Yii::$app->getRequest()->get("merchant_id");
        $order_no = \Yii::$app->getRequest()->get("order_no");
        $pay_method = \Yii::$app->getRequest()->get("pay_method");
        $status = \Yii::$app->getRequest()->get("status");
        $pay_status = \Yii::$app->getRequest()->get("pay_status");
        $is_adjust = \Yii::$app->getRequest()->get("is_adjust");
        $start_time = \Yii::$app->getRequest()->get("start_time");
        $end_time = \Yii::$app->getRequest()->get("end_time");
        $pagesize = \Yii::$app->getRequest()->get("pagesize");

        return [
            'list'=>GoodsOrderService::search($merchant_id,$order_no,$pay_method,$status,$pay_status,$is_adjust,$start_time,$end_time,$page,$pagesize),
            'page'=>$page->Out()
        ];
    }

    //获取信息
    public function actionGetInfoById($merchant_id,$id){
        return GoodsOrderService::getInfoById($merchant_id,$id);
    }

    //调单
    public function actionAdjust(){
        $form = new AdjustForm();
        if($form->load(\Yii::$app->getRequest()->post(),'') && GoodsOrderService::adjust($form)){
            return "";
        }else{
            throw new UserException(GoodsOrderService::getError());
        }
    }
}